;;(define (cond-frac n d k)
;;    (let ((n-value (n k))
;;          (d-value (d k)))
;;    (if (= k 1)
;;        (/ n-value d-value)
;;        (/ n-value (+ d-value
;;                      (cond-frac n d (- k 1)))))))
(define (cond-frac n d k)
    (let ((n-value (n k))
          (d-value (d k)))
    (define (iter n d k res)
        (if (= k 0)
            res
            (iter n d (- k 1) (/ n-value (+ d-value res)))))
    (iter n d k 0)))

(define (phi k)
    (cond-frac (lambda (i) 1.0)
               (lambda (i) 1.0)
                k))

(define (mod i x)
    (if (< i x)
        i
        (mod (- i x) x)))

(define (e k)
    (+ 2
    (cond-frac (lambda (i) 1.0)
               (lambda (i) (if (<= 1 (mod i 3))
                               1
                               (+ i (mod i 3))))
               k)))                               

(define (tan-cf x k)
    (cond-frac 
        (lambda (i) (if (= i 1.0) x (- (* x x))))
        (lambda (i) (- (* 2.0 i) 1.0))
        k))
            
